<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="jquery-3.4.1.min.js"></script>
    <script src="echarts.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="echarts" style="width: 100%; height: 480px;"></div>

    <script>
        function getData(data1, data2) {
            var numData = new Array;
            var codeNum = new Array;

            try {
                tmpstr = JSON.stringify(data1);
                substr = tmpstr.substring(2,tmpstr.length-2);
                numData = substr.split(',');
            }catch(exception) {
                alert(exception);
            }

            try {
                tmpstr = JSON.stringify(data2);
                substr = tmpstr.substring(2,tmpstr.length-2);
                codeNum = substr.split(',');
            }catch(exception) {
                alert(exception);
            }

            var dom = document.getElementById("echarts");
            var myChart = echarts.init(dom);
            option = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b} : {c}'
                },
                grid: {
                    left: '10%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value'

                },
                yAxis: {
                    type: 'category',
                    data: codeNum
                },
                series: [{
                    name: '前十位违法行为',
                    type: 'bar',
                    itemStyle:{
                        normal:{
                            color:function(params) {
                                var colorList = ["#080", "#00f", "#f00"];
                                return colorList[params.dataIndex];
                            },
                            label:{
                                show:true,
                                formatter:'{c}'
                            }
                        }
                    },
                    data: numData
                }]
            };
            myChart.setOption(option, true);
        }
    </script>
</body>
</html>